---
title: "Replication material for 'Why Do Citizens (Not) Support Democratic Innovations? The Role of Instrumental Motivations in Support for Participatory Budgeting'"

author: | 
        | Ramon van der Does
        | Jaroslaw Kantorowicz

date: |
      | January 18, 2021
      
output: html_notebook
---

# Installing/loading required packages

```{r}

#install.packages("cregg")
#install.packages("cjoint")
#install.packages("tidyverse")
#devtools::install_github("jaredhuling/jcolors")
#install.packages("ggpubr")
#install.packages("arm")
#install.packages("GGally")
#install.packages("grid")

library(cregg)
library(cjoint)
library(tidyverse)
library(jcolors)
library(ggpubr)
library(arm)
library(GGally)
library(grid)

```

# Load data for study 1

```{r}

rat <- read.csv(file="study_1.csv")

rat$residents_allowed_submit <- as.factor(rat$residents_allowed_submit)
rat$projects_allowed <- as.factor(rat$projects_allowed)
rat$support_municipality <- as.factor(rat$support_municipality)
rat$choice_winning_project <- as.factor(rat$choice_winning_project)
rat$outcome_favorability <- as.factor(rat$outcome_favorability)

```


# Testing for the presence of the carry-over effect

```{r}

cj_anova(rat, selected ~ 
              residents_allowed_submit +
              projects_allowed +
              support_municipality + 
              choice_winning_project +
              outcome_favorability, 
              by = ~task, 
              id = ~responseid)

```

# Constrain the dataset to only the first task and testing for profile order effect

```{r}

rat_task_1 <- rat %>% filter(task==1)
rat_task_1 %>% count()

rat_task_1$support_municipality <- factor(rat_task_1$support_municipality, 
                                          levels= c("No extra support", 
                                                    "Organizing discussion", 
                                                    "Helping to develop the project"))

cj_anova(rat_task_1, selected ~ 
                     residents_allowed_submit +
                     projects_allowed +
                     support_municipality + 
                     choice_winning_project +
                     outcome_favorability, 
                     by = ~profile, 
                     id = ~responseid)

```

# AMCE regression

```{r}

rat_task_1$support_municipality <- factor(rat_task_1$support_municipality, 
                                          levels= c("No extra support", 
                                                    "Organizing discussion", 
                                                    "Helping to develop the project"))

rat_amce <- cj(rat_task_1,
              selected ~ 
              residents_allowed_submit + 
              projects_allowed + 
              support_municipality + 
              choice_winning_project + 
              outcome_favorability, 
              id = ~responseid, 
              estimate = "amce",
              feature_order = c("residents_allowed_submit",
                                "projects_allowed",
                                "support_municipality",
                                "choice_winning_project",
                                "outcome_favorability"),
              feature_labels = c(residents_allowed_submit = "Who can submit a project?", 
                                 projects_allowed = "What projects are allowed?",
                                 outcome_favorability = "Is the outcome favorable?", 
                                 support_municipality = "Does the muninicipality offer any support?", 
                                 choice_winning_project="Who is choosing the winning project?"))

```


# Figure 2 Results study 1

```{r}

plot_rat_amce <- plot(rat_amce, 
                     vline=0.0, 
                     size=1, 
                     feature_headers = FALSE)

plot_rat_amce_final <- plot_rat_amce +
           theme(legend.position="none") + 
           theme(axis.text.y = element_text(colour = "black")) +
           theme(axis.text.x = element_text(colour = "black")) +
           theme(plot.title = element_text(hjust = 1.0, vjust = 3)) +
           theme(text = element_text(size=15))  +
           ggplot2::facet_wrap(~feature, ncol=1, scales = "free_y") +
           geom_text(subset(rat_amce, estimate!=0), mapping=aes(label=round(estimate,3)), 
                     parse = TRUE, color="black", size=3, check_overlap = TRUE, 
                     vjust = 1.4) +
           scale_color_jcolors("pal11") +
           theme(panel.grid.major = element_blank(),
           panel.grid.minor = element_blank(),
           strip.background = element_blank(),
           panel.border = element_rect(colour = "black")) +
          labs(y = "", x = "Estimated AMCE")
            

plot(plot_rat_amce_final)

plot_rat_amce_final %>% ggsave(filename = "figure_1.png",
                               width = 8, 
                               height = 8, 
                               dpi = 150, 
                               units = "in", 
                               device='png')

```

